<?php
/* Phân trang */

public function pagination($url, $page, $total)
{
    $adjacents = 2;
    $prevlabel = "&laquo; Trước";
    $nextlabel = "Tiếp &raquo;";
    $out       = '<ul class="pagination">';
    
    //first
    if ($page == 1) {
        $out .= '<li class="disabled"><span>Đầu</span></li>';
    } else {
        $out .= '<li><a href="' . $url . '">Đầu</a></li>';
    }
    
    // previous
    if ($page == 1) {
        $out .= '<li class="disabled"><span>&laquo;</span></li>';
    } elseif ($page == 2) {
        $out .= '<li><a href="' . $url . '">&laquo;</a></li>';
    } else {
        $out .= '<li><a href="' . $url . '&amp;page=' . ($page - 1) . '">&laquo;</a></li>';
    }
    
    $pmin = ($page > $adjacents) ? ($page - $adjacents) : 1;
    $pmax = ($page < ($total - $adjacents)) ? ($page + $adjacents) : $total;
    for ($i = $pmin; $i <= $pmax; $i++) {
        if ($i == $page) {
            $out .= '<li class="active"><span>' . $i . '</span></li>';
        } elseif ($i == 1) {
            $out .= '<li><a href="' . $url . '">' . $i . '</a></li>';
        } else {
            $out .= '<li><a href="' . $url . "&amp;page=" . $i . '">' . $i . '</a></li>';
        }
    }
    
    // next
    if ($page < $total) {
        $out .= '<li><a href="' . $url . '&amp;page=' . ($page + 1) . '">&raquo;</a></li>';
    } else {
        $out .= '<li class="disabled"><span>&raquo;</span></li>';
    }
    
    //last
    if ($page < $total) {
        $out .= '<li><a href="' . $url . '&amp;page=' . $total . '">Cuối</a></li>';
    } else {
        $out .= '<li class="disabled"><span>Cuối</span></li>';
    }
    
    $out .= '<input class="current-page" type="text" name="pagecurrent" size="1" value="' . $page . '" /> <label class="current-page2">of ' . $total . '</label>';
    $out .= '</ul>';
    return $out;
}

?>